import pygame

from actor import DirShootByAImage, ShootDir, WalkDir
from actor.walk_soldier import WalkSoldier


class ShootSoldier(WalkSoldier):
    shoot_image_width = 100
    shoot_image_height = 100

    def __init__(self, walk_image_path: str, shoot_image_path: str, x: int, y: int, name: str, hp: int):
        super(ShootSoldier, self).__init__(walk_image_path, x, y, name, hp)

        self.shoot_action = DirShootByAImage(shoot_image_path, self.shoot_image_width, self.shoot_image_height,
                                             True)

    def draw(self, surface: pygame.Surface, x, y):
        if self.shoot_action.shoot_dir == ShootDir.not_shoot:
            super(ShootSoldier, self).draw(surface, x, y)
        elif self.shoot_action.shoot_dir == ShootDir.down:
            image = self.shoot_action.get_image()
            surface.blit(image, (self.pos_x - x, self.pos_y - y))
            image = self.walk_action.get_image()
            surface.blit(image, (self.pos_x - x, self.pos_y - y))
        elif self.shoot_action.shoot_dir == ShootDir.up:
            image = self.shoot_action.get_image()
            surface.blit(image, (self.pos_x - x, self.pos_y - y - 60))
            image = self.walk_action.get_image()
            surface.blit(image, (self.pos_x - x, self.pos_y - y))
        else:
            image = self.shoot_action.get_image()
            surface.blit(image, (self.pos_x - x, self.pos_y - y))

    def run(self, down_flag, key_list):
        super(ShootSoldier, self).run(down_flag, key_list)
        if key_list[pygame.K_q]:
            self.shoot_action.set_dir(ShootDir.left_up)
        elif key_list[pygame.K_a]:
            self.shoot_action.set_dir(ShootDir.left_down)
        elif key_list[pygame.K_e]:
            self.shoot_action.set_dir(ShootDir.right_up)
        elif key_list[pygame.K_d]:
            self.shoot_action.set_dir(ShootDir.right_down)
        elif key_list[pygame.K_w]:
            self.shoot_action.set_dir(ShootDir.up)
            self.walk_action.set_dir(WalkDir.up)  # 闪烁的效果与行走的方向匹配（因为上下射击是没有图片的只有效果，防止面向左右而向
            # 上射击的情况产生）
        elif key_list[pygame.K_s]:
            self.shoot_action.set_dir(ShootDir.down)
            self.walk_action.set_dir(WalkDir.down)
